package com.wangyu.springsecuritydemo.repository.secondary;

import com.wangyu.springsecuritydemo.controller.to.HourseInfoTo;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

/**
 * @Author wangyu
 * @Date 2019/2/22 16:28
 * @Version 1.0
 */
@Repository
public class UserInfoDao {

  @Autowired
  private JdbcTemplate jdbcTemplate;

  public List<HourseInfoTo> findAll() {
    String sql = "select projectId,name from gbd_project_info";
    List<HourseInfoTo> query = jdbcTemplate.query(sql, new RowMapper<HourseInfoTo>() {
      @Override
      public HourseInfoTo mapRow(ResultSet resultSet, int i) throws SQLException {
        HourseInfoTo hourseInfoTo = new HourseInfoTo();
        hourseInfoTo.setProjectId(resultSet.getString(1));
        hourseInfoTo.setName(resultSet.getString(2));
        return hourseInfoTo;
      }
    });
    return query;
  }

}
